package com.tcj.myprogram.memorialday;

import android.content.Intent;
import android.os.Bundle;
import android.widget.FrameLayout;

import com.tcj.myprogram.memorialday.myview.MyViewFactory;


/**
 * Main Activity
 * @author tsengchienjung
 *
 */
public class MainActivity extends BaseActivity  {

	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// 設定內容
		setContentView(R.layout.activity_main);

		// 取得MyView的class name
		String name = null;
		name = this.getIntent().getStringExtra(INTENT_KEY_VIEW_NAME);
		if (null == name) {
			// 預設值
			name = MY_VIEW_MAIN;
		}

		// layout中的一大塊空白
		FrameLayout content = (FrameLayout) findViewById(R.id.content);

		// 取得MyView
		try {
			myView = MyViewFactory.getMyViewInstance(this, name);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (null != myView) {
			myView.doOnCreate(this.getIntent().getExtras());
			// 用MyView將空白填滿
			content.addView(myView.getView());
		}
		// 要不要顯示廣告的設定(有些頁面若不想顯示廣告，可從MyView中的showAd的參數調整)
		if (!(null != myView && !myView.isShowAD())) {
			setAd();
		}

	}

	@Override
	protected void onResume() {
		super.onResume();
		// 判斷目前是那一個Tab被使用
	}

	@Override
	// 用在facebook做完事之後
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (null != myView) {
			myView.doOnActivityResult(requestCode, resultCode, data);
		}
	}

}
